#include<unistd.h>
#include<fcntl.h>
#include<string.h>
#include<sys/mman.h>
#include<sys/stat.h>
#include<stdlib.h>
#include<stdio.h>
#include<errno.h>
int main(int argc,char** argv)
{

    int fd;
    fd=open("mmaptest",O_RDWR|O_CREAT|O_TRUNC);

    if(fd==-1)
    {
        perror("open fail!\n");

      }
    char *p=NULL;
    int size;

    //获取创建文件的大小
    lseek(fd,20,SEEK_END);
    write(fd,"\0",1);//实际扩容的文件大小是21
    size=lseek(fd,0,SEEK_END);


    p=mmap(NULL,size,PROT_READ| PROT_WRITE,MAP_SHARED,fd,0);

    if(p==MAP_FAILED)
    {
        perror("mmmap fail\n");

        
        
        }

    char *str="hello ubuntn!\n";
    strcpy(p,str);

    printf("p=%s\n",p);
    
return 0;
}
